package edu.hebeu.evil.freshmenguide.Activity;

import android.content.Intent;
import android.support.annotation.DrawableRes;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import cn.iwgang.familiarrecyclerview.FamiliarRecyclerView;
import edu.hebeu.evil.freshmenguide.R;

/********************************************
 * 工程名：FreshmenGuide
 * 包名：edu.hebeu.evil.freshmenguide.Activity
 * 时间：16-7-20 下午6:56
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：校园地图
 ********************************************/
public class SchoolMapActivity extends BaseActivity
{
    private FamiliarRecyclerView recyclerView;


    private Adapter adapter;
    private ArrayList<ItemBean> list;

    @Override
    public int setContentView()
    {
        return R.layout.schoolmap;
    }

    @Override
    public String setToolbarTitle()
    {
        return "校园地图";
    }

    @Override
    public void onCreate()
    {
        initView();
        setRecyclerView();/*设置RecyclerView*/
    }

    /**
     * 初始化控件
     */
    private void initView()
    {
        recyclerView = (FamiliarRecyclerView) findViewById(R.id.recyclerView);
    }

    /**
     * 设置RecyclerView
     */
    private void setRecyclerView()
    {
        list = new ArrayList<>();
        adapter = new Adapter();

        list.add(new ItemBean("本部 校区", R.drawable.maps_benbu
                , getResources().getString(R.string.content_benbu)));
        list.add(new ItemBean("中华南 校区", R.drawable.maps_zhonghuanan
                , getResources().getString(R.string.content_zhonghuanan)));
        list.add(new ItemBean("丛台 校区", R.drawable.maps_congtai
                , getResources().getString(R.string.content_congtai)));

        recyclerView.setAdapter(adapter);


        recyclerView.setOnItemClickListener(new FamiliarRecyclerView.OnItemClickListener()
        {
            @Override
            public void onItemClick(FamiliarRecyclerView familiarRecyclerView, View view, int position)
            {
                startActivity(new Intent(SchoolMapActivity.this, ImageZoom.class).putExtra("IMGRES", list.get(position).imgRes));
            }
        });

    }

    private class Adapter extends RecyclerView.Adapter<ViewHolder>
    {
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
        {
            View view = LayoutInflater.from(SchoolMapActivity.this)
                    .inflate(R.layout.schoolmap_item, parent, false);

            return new ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position)
        {
            holder.title.setText(list.get(position).title);
            Glide.with(SchoolMapActivity.this).load(list.get(position).imgRes).into(holder.imageView);
            holder.content.setText(list.get(position).content);
        }

        @Override
        public int getItemCount()
        {
            return list.size();
        }
    }

    private class ViewHolder extends RecyclerView.ViewHolder
    {
        private TextView title;
        private ImageView imageView;
        private TextView content;

        public ViewHolder(View itemView)
        {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title);
            imageView = (ImageView) itemView.findViewById(R.id.imageView);
            content = (TextView) itemView.findViewById(R.id.content);
        }
    }

    private class ItemBean
    {
        private String title;
        @DrawableRes
        private int imgRes;

        private String content;

        public ItemBean(String title, int imgRes, String content)
        {
            this.title = title;
            this.imgRes = imgRes;
            this.content = content;
        }
    }
}
